# -*- coding:utf-8 -*-
from ppts.entity.TestUrl import TestUrl
import datetime


class TestConfig:

    def __init__(self, config):
        self.start_script = config.get('start_script', None)
        self.browser_type = config.get('browser_type', 'chrome')
        self.user_agent = config.get('user_agent', '')
        self.driver_path = config.get('driver_path', None)
        self.no_headless = config.get('no_headless', False)
        self.repeat = config.get('repeat', 10)
        self.test_interval_time = config.get('test_interval_time', 1)
        self.page_load_timeout = config.get('page_load_timeout', 30)
        self.cache = config.get('cache', False)
        self.report_name = config.get('report_name', datetime.datetime.now().strftime('%Y%m%d%H%M%S'))
        self.report_type = config.get('report_type', 'html')
        self.complete_script = config.get('complete_script', None)
        self.pass_time = config.get('pass_time', 3000)
        self.challenge_time = config.get('challenge_time', 2000)
        self.custom_cookie = config.get('custom_cookie', '')
        self.browser_path = config.get('browser_path', '')

        self.cookie_list = []

        self.start_time = ''
        self.complete_time = ''
        self.use_time = 0

        self.test_urls = []
        if len(config.get('test_urls', [])) > 0:
            for c in config.get('test_urls', []):
                self.test_urls.append(TestUrl(config=c, pass_time=self.pass_time, challenge_time=self.challenge_time))

        if self.custom_cookie:
            temp_list = self.custom_cookie.split(';')
            for temp in temp_list:
                temp2_list = str(temp).split('=', 1)
                self.cookie_list.append({
                    'name': temp2_list[0].strip(),
                    'value': temp2_list[1].strip()
                })

